package es.javamyadmin.ajax;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.javamyadmin.dao.TablesDAO;


public class EditarCampoAjax extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String user = request.getParameter("usuario");
		String pass = request.getParameter("pass");
		String host = request.getParameter("servidor");
		String port = request.getParameter("puerto");
		String database = request.getParameter("bd");
		String tabla = request.getParameter("tabla");
		String fila = request.getParameter("fila");
		String columna = request.getParameter("columna");
		String valor = request.getParameter("valor");
		
		TablesDAO table = new TablesDAO();
		String respuesta = "";
		if(!table.updateCampo(user, pass, host, port, database, tabla,valor, Integer.parseInt(columna), Integer.parseInt(fila))){
			respuesta = valor;
		}
		else{
			respuesta = "Error no se ha podido asignar el valor";
		}
		PrintWriter out = response.getWriter();
		try{
			out.print(respuesta);
		}finally{
			out.close();
		}
	}

}